package com.pad.producter.controller;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pad.dpscn.daag.sdk.core.annotation.DataSendPosition;
import com.pad.producter.domain.Students;
import com.pad.producter.result.JSONResult;
import com.pad.producter.service.IStudentsService;

import lombok.extern.slf4j.Slf4j;

/**
 * @desc
 * @author yangdechao
 * @since 2024-2-27
 * 主要用于联合主键测试
 */
@RestController
@RequestMapping("/students")
@Slf4j
@DataSendPosition
public class StudentsController {

	@Autowired
	public IStudentsService studentsService;

	/**
	 * 保存和修改操作公用此方法
	 * 
	 * @param operLog 前端传递来的实体数据
	 */
	@GetMapping(value = "/selectById/{id}")
	public JSONResult selectById(@PathVariable("id") Long id) {
		Students entity = studentsService.selectById(id);
		return JSONResult.success(entity);
	}

	/**
	 * 保存和修改操作公用此方法
	 * 
	 * @param operLog 前端传递来的实体数据
	 */
	@PostMapping(value = "/save")
	public JSONResult save(@RequestBody Students students) {
		log.info("======================业务执行开始=====================");
		students.setStudentId(UUID.randomUUID().toString());
		students.setCourseId(UUID.randomUUID().toString());
		studentsService.insert(students);
		log.info("======================业务执行结束=====================");

		return JSONResult.success();
	}

}